package com.android.BluethootChess.rules;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Point;

import com.android.BluethootChess.model.GameBoardMatrix;
import com.android.BluethootChess.model.PieceColor;

/**
 * KnightRules clasa care implementeaza interfata PieceRulesInterface si defineste 
 * regulile pentru piesa cal. 
 * 
 * @see PieceRule
 */
public class KnightRules extends PieceRule {

	
	public KnightRules(GameBoardMatrix matrix, PieceColor pieceColor) {
		super(matrix, pieceColor);
	}
	
	
	public List<Point> findAllAvaiblePositions() {
		List<Point> list = new ArrayList<Point>();
		
		int linie = piecePosition.x; 
		int coloana = piecePosition.y;

		// case 1
		if (isValidLocation(linie + 2, coloana - 1)) {
			list.add(new Point(linie + 2, coloana - 1));
		}

		// case 2
		if (isValidLocation(linie + 2, coloana + 1)) {
			list.add(new Point(linie + 2, coloana + 1));
		}

		// case 3
		if (isValidLocation(linie + 1, coloana + 2)) {
			list.add(new Point(linie + 1, coloana + 2));
		}

		// case 4
		if (isValidLocation(linie + 1, coloana - 2)) {
			list.add(new Point(linie + 1, coloana - 2));
		}

		// case 5
		if (isValidLocation(linie - 2, coloana + 1)) {
			list.add(new Point(linie - 2, coloana + 1));
		}

		// case 6
		if (isValidLocation(linie - 2, coloana - 1)) {
			list.add(new Point(linie - 2, coloana - 1));
		}

		// case 7
		if (isValidLocation(linie - 1, coloana + 2)) {
			list.add(new Point(linie - 1, coloana + 2));
		}

		// case 8
		if (isValidLocation(linie - 1, coloana - 2)) {
			list.add(new Point(linie - 1, coloana - 2));
		}
		return list;
	}

}
